/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class CoordenadasDAOImpl implements orm.dao.CoordenadasDAO {
	public Coordenadas loadCoordenadasByORMID(int id_coordenada) throws PersistentException {
		try {
			PersistentSession session = orm.PDSTablaAutentificacionPersistentManager.instance().getSession();
			return loadCoordenadasByORMID(session, id_coordenada);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenadas getCoordenadasByORMID(int id_coordenada) throws PersistentException {
		try {
			PersistentSession session = orm.PDSTablaAutentificacionPersistentManager.instance().getSession();
			return getCoordenadasByORMID(session, id_coordenada);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenadas loadCoordenadasByORMID(int id_coordenada, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PDSTablaAutentificacionPersistentManager.instance().getSession();
			return loadCoordenadasByORMID(session, id_coordenada, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenadas getCoordenadasByORMID(int id_coordenada, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PDSTablaAutentificacionPersistentManager.instance().getSession();
			return getCoordenadasByORMID(session, id_coordenada, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenadas loadCoordenadasByORMID(PersistentSession session, int id_coordenada) throws PersistentException {
		try {
			return (Coordenadas) session.load(orm.Coordenadas.class, new Integer(id_coordenada));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenadas getCoordenadasByORMID(PersistentSession session, int id_coordenada) throws PersistentException {
		try {
			return (Coordenadas) session.get(orm.Coordenadas.class, new Integer(id_coordenada));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenadas loadCoordenadasByORMID(PersistentSession session, int id_coordenada, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Coordenadas) session.load(orm.Coordenadas.class, new Integer(id_coordenada), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenadas getCoordenadasByORMID(PersistentSession session, int id_coordenada, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Coordenadas) session.get(orm.Coordenadas.class, new Integer(id_coordenada), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenadas[] listCoordenadasByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.PDSTablaAutentificacionPersistentManager.instance().getSession();
			return listCoordenadasByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenadas[] listCoordenadasByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PDSTablaAutentificacionPersistentManager.instance().getSession();
			return listCoordenadasByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenadas[] listCoordenadasByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Coordenadas as Coordenadas");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Coordenadas[]) list.toArray(new Coordenadas[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenadas[] listCoordenadasByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Coordenadas as Coordenadas");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Coordenadas[]) list.toArray(new Coordenadas[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenadas loadCoordenadasByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.PDSTablaAutentificacionPersistentManager.instance().getSession();
			return loadCoordenadasByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenadas loadCoordenadasByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PDSTablaAutentificacionPersistentManager.instance().getSession();
			return loadCoordenadasByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenadas loadCoordenadasByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Coordenadas[] coordenadases = listCoordenadasByQuery(session, condition, orderBy);
		if (coordenadases != null && coordenadases.length > 0)
			return coordenadases[0];
		else
			return null;
	}
	
	public Coordenadas loadCoordenadasByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Coordenadas[] coordenadases = listCoordenadasByQuery(session, condition, orderBy, lockMode);
		if (coordenadases != null && coordenadases.length > 0)
			return coordenadases[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateCoordenadasByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.PDSTablaAutentificacionPersistentManager.instance().getSession();
			return iterateCoordenadasByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateCoordenadasByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PDSTablaAutentificacionPersistentManager.instance().getSession();
			return iterateCoordenadasByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateCoordenadasByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Coordenadas as Coordenadas");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateCoordenadasByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Coordenadas as Coordenadas");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenadas createCoordenadas() {
		return new orm.Coordenadas();
	}
	
	public boolean save(orm.Coordenadas coordenadas) throws PersistentException {
		try {
			orm.PDSTablaAutentificacionPersistentManager.instance().saveObject(coordenadas);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Coordenadas coordenadas) throws PersistentException {
		try {
			orm.PDSTablaAutentificacionPersistentManager.instance().deleteObject(coordenadas);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Coordenadas coordenadas)throws PersistentException {
		try {
			if(coordenadas.getTarjetaid_tarjeta() != null) {
				coordenadas.getTarjetaid_tarjeta().coordenadas.remove(coordenadas);
			}
			
			return delete(coordenadas);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Coordenadas coordenadas, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(coordenadas.getTarjetaid_tarjeta() != null) {
				coordenadas.getTarjetaid_tarjeta().coordenadas.remove(coordenadas);
			}
			
			try {
				session.delete(coordenadas);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Coordenadas coordenadas) throws PersistentException {
		try {
			orm.PDSTablaAutentificacionPersistentManager.instance().getSession().refresh(coordenadas);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Coordenadas coordenadas) throws PersistentException {
		try {
			orm.PDSTablaAutentificacionPersistentManager.instance().getSession().evict(coordenadas);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Coordenadas loadCoordenadasByCriteria(CoordenadasCriteria coordenadasCriteria) {
		Coordenadas[] coordenadases = listCoordenadasByCriteria(coordenadasCriteria);
		if(coordenadases == null || coordenadases.length == 0) {
			return null;
		}
		return coordenadases[0];
	}
	
	public Coordenadas[] listCoordenadasByCriteria(CoordenadasCriteria coordenadasCriteria) {
		return coordenadasCriteria.listCoordenadas();
	}
}
